/**
 *
 */
package com.aerozhonghuan.logisticsmall.modules.home;

import android.content.Context;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import java.util.List;

public class ImageViewsViewPagerAdapter extends PagerAdapter {

    private List<ImageView> list;
    private Context context;

    public ImageViewsViewPagerAdapter(Context c, List<ImageView> list) {
        this.list = list;
        this.context = c;
    }

    @Override
    public void destroyItem(View view, int position, Object arg2) {
        ViewPager pViewPager = ((ViewPager) view);
        pViewPager.removeView(list.get(position));
    }

    @Override
    public void finishUpdate(View arg0) {
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object instantiateItem(View view, int position) {
        ViewPager pViewPager = ((ViewPager) view);
        View v = list.get(position);
        pViewPager.addView(v);
        int productId = 12013; //替换为商品id
        v.setOnClickListener(new viewListener(position, productId));
        return list.get(position);
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == arg1;
    }

    @Override
    public void restoreState(Parcelable arg0, ClassLoader arg1) {
    }

    @Override
    public Parcelable saveState() {
        return null;
    }

    @Override
    public void startUpdate(View arg0) {
    }

    class viewListener implements OnClickListener {
        int position;
        int productId;

        public viewListener(int position, int product_id) {
            this.position = position;
            this.productId = product_id;
        }

        @Override
        public void onClick(View v) {
            Log.d("community", "========" + position);
            /*Intent intent = new Intent();
            intent.setClass(context, GoodsDetailsActivity.class);
            intent.putExtra("product_id", productId);
            context.startActivity(intent);*/
        }

    }
}
